package com.example.myapplication.DataBase;

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import com.example.myapplication.ContentTest.ContentActivity;
import com.example.myapplication.MainActivity;
import com.example.myapplication.Media.MediaActivity;
import com.example.myapplication.R;

public class DataStoreActivity extends AppCompatActivity {
  @Override protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.database_layout);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("数据持久化测试");

    setSupportActionBar(toolbar);
    BindButton();


  }

  private void BindButton() {
    Button sharedButton = (Button) findViewById(R.id.shared_button);
    Button sqlButton = (Button) findViewById(R.id.sql_button);
    sharedButton.setOnClickListener(new View.OnClickListener() {
      @Override public void onClick(View v) {
        JumpToPreferencesActivity();
        
      }
    });
    sqlButton.setOnClickListener(new View.OnClickListener() {
      @Override public void onClick(View v) {
        JumpToDataBaseActivity();
      }
    });
  }

  private void JumpToDataBaseActivity() {
    Intent intent = new Intent(this, LiteActivity.class);
    startActivity(intent);
  }

  private void JumpToPreferencesActivity() {
    Intent intent=new Intent(this, PreferencesActivity.class);
    startActivity(intent);

  }

  @Override public boolean onCreateOptionsMenu(Menu menu) {
    menu.add(0, 1, 0, "返回上一个Activity");
    menu.add(0, 2, 1, "跳到下一个Activity");
    return true;
  }
  @Override public boolean onOptionsItemSelected(@NonNull MenuItem item) {
    switch (item.getItemId()) {
      case 1:
        BackToLastActivity();
        break;
      case 2:
        GoToNextActivity();
        break;
    }
    return true;
  }
  private void GoToNextActivity() {
    Intent intent = new Intent(this, ContentActivity.class);
    startActivity(intent);
  }
  private void BackToLastActivity() {
    Intent intent = new Intent(this, MediaActivity.class);
    startActivity(intent);

  }
}
